""" Models/Services Model """

from masoniteorm.models import Model
from masoniteorm.scopes import scope
from masoniteorm.relationships import has_many

from config.config import cache


class Services(Model):
    """Models/Services Model"""
    __fillable__ = ['name_zh', 'is_menu', 'name_ug', 'images', 'description', 'vip_benefit', 'cid']
    __hidden__ = ['name_zh', 'name_ug', 'is_delete', 'sort', 'region', 'city', 'province']
    __appends__ = ['name']

    def get_name_attribute(self):
        lan = cache.get('lan')
        if lan == 'ug':
            return self.name_ug
        return self.name_zh

    @has_many('id', 'sid')
    def scopes(self):
        from app.models.ServicesScopes import ServicesScopes
        return ServicesScopes

    @scope
    def city(self, query):
        province = cache.get('province')
        region = cache.get('region')
        city = cache.get('city')
        if province is not None:
            print(province)
            query.where('province', province)
        if region is not None:
            query.where('region', region)
        if city is not None:
            query.where('city', city)
        return query
